package com.hpeu_01.Rollcall;

import java.util.*;

/**
 * 点名系统
 */
public class Rollcall {
    private static Scanner scanner = new Scanner(System.in);
    private static Random random = new Random();
    //点名方法
    public static void method(){
        String[] str={"孙尚香","钟无艳","阿轲","伽罗","公孙离","米莱狄","上官婉儿","西施","杨玉环","瑶","元歌","花木兰","雅典娜","不知火舞","娜可露露","夏洛特","安琪拉","蔡文姬","嫦娥","妲己"};
        ArrayList<String> list = new ArrayList<>();
        for (String s : str) {
            list.add(s);
        }

        HashSet set = new HashSet();
        System.out.println("欢迎来到王者荣耀，总人数为："+str.length);
        System.out.println("请输入你要抽取英雄的个数：");
        int num = scanner.nextInt();
        if (num>0 && num<= str.length){
            for (int i=0;i<num;i++){
                int index = random.nextInt(str.length);
                if (set.add(index)){
                    System.out.print(list.get(index)+" ");
                }else {
                    i--;
                }
            }
        }
        System.out.println();
    }

    public static int dropout(){
        int i=0;
        System.out.println("你确定要退出系统？是则按Y，否则按N");
        String s = scanner.nextLine().toUpperCase();
        if ("Y".equals(s)||"N".equals(s)){
            if ("Y".equals(s)){
                System.out.println("你已退出系统!");
                return i=1;
            }
        }else {
            System.out.println("输入错误！");
        }
        return i;
    }
}
class RollcallDemo{
    public static void main(String[] args) {
        boolean flge = true;
        while (flge){
            Scanner scanner = new Scanner(System.in);
            System.out.println("******************欢迎进入随机点名系统****************");
            System.out.println("1：随机点名");
            System.out.println("2:退出");
            System.out.println("请输入相应指令：");
            int choose = scanner.nextInt();
            switch (choose){
                case 1:
                    Rollcall.method();
                    break;
                case 2:
                    int dropout = Rollcall.dropout();
                    if (dropout==1){
                        flge=false;
                    }
                    break;
                default:
                    System.out.println("输入错误请重新输入：");
            }
        }
    }
}